package com.blate.dogxiao.activity;

import android.content.Intent;
import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;

import com.blate.dogxiao.R;
import com.blate.dogxiao.bean.HouseBean;
import com.blate.dogxiao.databinding.ActivityHouseDetailBinding;
import com.bumptech.glide.Glide;

/**
 * @author Blate
 * Created in 2021/4/21
 */
public class HouseDetailActivity
        extends AppCompatActivity {

    public static final String KEY_HOUSE_BEAN = "key_house_bean";

    private ActivityHouseDetailBinding mBinding;

    private HouseBean mHouseBean;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mBinding = DataBindingUtil.setContentView(this, R.layout.activity_house_detail);
        readExtra(getIntent());
        initialize();
    }

    private void readExtra(Intent intent) {
        mHouseBean = intent.getParcelableExtra(KEY_HOUSE_BEAN);
    }

    private void initialize() {
        mBinding.topBar.setNavigationOnClickListener(v -> finish());
        loadHouseDataToUi(mHouseBean);
    }

    private void loadHouseDataToUi(HouseBean houseBean) {
        if (houseBean == null) {
            return;
        }
        Glide
                .with(this)
                .load(houseBean.preview)
                .into(mBinding.ivPreview);
        mBinding.tvTitle.setText(houseBean.title);
        mBinding.tvSummary.setText(houseBean.summary);
        mBinding.tvUnitPrice.setText(houseBean.unitPrice);
        mBinding.tvTotalPrice.setText(houseBean.totalPrice);
        mBinding.tvAreaDetail.setText(houseBean.areaDetail);
    }

}
